<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>无标题文档</title>
  <link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="../../js/jquery.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <script type="text/javascript" src="../../js/axios.js"></script>
  <script type="text/javascript" src="../../layui/layui.js"></script>
  <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>厂商管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post" id="conn">
    <ul class="tools">
      <li> 公司名称:
        <input type="text" name="firmName"/>
      </li>
      <li> 负责人姓名:
        <input type="text" name="firmFounder"/>
      </li>
      <li> 所属区域：
        <select name="pId" id="pId">
<!--          <option value="0">请选择省份</option>-->
<!--          <option>北京</option>-->
<!--          <option>江苏</option>-->
<!--          <option>天津</option>-->
        </select>
        <select name="firmCity" id="firmCity">
<!--          <option value="0">请选择城市</option>-->
<!--          <option>北京</option>-->
<!--          <option>南京</option>-->
<!--          <option>天津</option>-->
        </select>
      </li>
      <li> 状态：
        <select name="status">
          <option value="0">请选择</option>
          <option value="1">可用</option>
          <option value="2">不可用</option>
        </select>
      </li>
      <li class="subBut" id="search"><img src="../../images/t06.png" />查询</li>
      <li class="subBut" onclick="window.location.href='manufacturerAdd.html'"><img src="../../images/t01.png" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
      <tr>
        <th>序号</th>
        <th>厂商名称</th>
        <th>负责人</th>
        <th>联系电话</th>
        <th>所属区域</th>
        <th>状态</th>
        <th>创建时间</th>
        <th>创建人</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody id="tList">
      <!--        <tr>-->
      <!--          <td>1</td>-->
      <!--          <td>阿里巴巴</td>-->
      <!--          <td>王金平</td>-->
      <!--          <td>17370899727</td>-->
      <!--          <td>江苏南京</td>-->
      <!--          <td>可用</td>-->
      <!--          <td>2013-09-09 15:05:05</td>-->
      <!--          <td>管理员</td>-->
      <!--          <td>-->
      <!--          	<a href="manufacturerView.html" class="tablelink">查看详情</a>-->
      <!--            <a href="manufacturerUpdate.html" class="tablelink">修改</a>-->
      <!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
      <!--          </td>-->
      <!--        </tr>-->
      <!--        <tr>-->
      <!--          <td>2</td>-->
      <!--          <td>腾讯公司</td>-->
      <!--          <td>张永祥</td>-->
      <!--          <td>17370897894</td>-->
      <!--          <td>江苏南京</td>-->
      <!--          <td>不可用</td>-->
      <!--          <td>2013-09-09 15:05:05</td>-->
      <!--          <td>管理员</td>-->
      <!--          <td>-->
      <!--          	<a href="manufacturerView.html" class="tablelink">查看详情</a>-->
      <!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
      <!--          </td>-->
      <!--        </tr>-->
      <!--        <tr>-->
      <!--          <td>3</td>-->
      <!--          <td>阿里巴巴</td>-->
      <!--          <td>王金平</td>-->
      <!--          <td>17370899727</td>-->
      <!--          <td>江苏南京</td>-->
      <!--          <td>可用</td>-->
      <!--          <td>2013-09-09 15:05:05</td>-->
      <!--          <td>管理员</td>-->
      <!--          <td>-->
      <!--          	<a href="manufacturerView.html" class="tablelink">查看详情</a>-->
      <!--            <a href="manufacturerUpdate.html" class="tablelink">修改</a>-->
      <!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
      <!--          </td>-->
      <!--        </tr>-->
      <!--        <tr>-->
      <!--          <td>3</td>-->
      <!--          <td>腾讯公司</td>-->
      <!--          <td>张永祥</td>-->
      <!--          <td>17370897894</td>-->
      <!--          <td>江苏南京</td>-->
      <!--          <td>不可用</td>-->
      <!--          <td>2013-09-09 15:05:05</td>-->
      <!--          <td>管理员</td>-->
      <!--          <td>-->
      <!--          	<a href="manufacturerView.html" class="tablelink">查看详情</a>-->
      <!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
      <!--          </td>-->
      <!--        </tr>-->
      </tbody>
    </table>
    <div class="pagin" id="page">
      <!--      <div class="message">共<i class="blue">1256</i>条记录，当前显示第&nbsp;<i class="blue">2&nbsp;</i>页</div>-->
      <!--      <ul class="paginList">-->
      <!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;">1</a></li>-->
      <!--        <li class="paginItem current"><a href="javascript:;">2</a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
      <!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
      <!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
      <!--      </ul>-->
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>

  </div>
</div>
<script type="text/javascript">
  $('.tablelist tbody tr:odd').addClass('odd');

  let pageSize=5;
  let pageNum=1;
  let conn='';
  $(function () {
    loadPurchase(1, pageSize,conn)
    addressMenuInitOfDefault($('#pId'),$('#firmCity'),0,0);
    //查询点击事件
    $('#search').click(function () {
      conn = $('#conn').serializeArray()
      // console.log(conn)
      loadPurchase(1,pageSize,conn)
    });
  })

  function tipOpen(content,firmId,status) {
    $(".tipright p").text(content);
    $("#tip").fadeIn(200);
    $('.sure').unbind('click').click(function () {
      axiosJson(
              'get',//提交方法
              '/purchase/lorFirm',//提交地址
              null,
              {firmId: firmId, status: status}
      ).then(() => {
        loadPurchase(pageNum, pageSize,conn);
        tipClose();
      })
    })
  }

  function tipClose() {
    $("#tip").fadeOut(200);
  }



  //加载数据
  function loadPurchase(pageNum, pageSize,conn) {
    axiosJson(
            'get',//提交方法
            '/purchase/firmPage',//提交地址
            conn,
            {pageNum: pageNum, pageSize: pageSize}
    ).then((res) => {
      // console.log(res);
      // alert('提交成功！');
      writeData(res)
    })
  }

  //写数据
  function writeData(res) {
    let str = ''
    let audit = res.data.resultData.data  //pageModel里purchase的数据
    let page = res.data.resultData   //查看pageModel 的属性值
    // console.log(page)
    for (let i=0;i<audit.length;i++){
      let status='';
      let lor='';
      if (audit[i].status==1){
        status='可用';
        lor='<a href="manufacturerUpdate.html?id='+audit[i].firmId+'" class="tablelink">修改 </a>'+
                '<a href="javascript:void(0)" class="tablelink" onclick="tipOpen(\'是否确认注销此条信息？\','+audit[i].firmId+','+audit[i].status+')">注销</a>\n';
      }else {
        status='不可用';
        lor='<a href="javascript:void(0)" class="tablelink" onclick="tipOpen(\'是否确认恢复此条信息？\','+audit[i].firmId+','+audit[i].status+')">恢复</a>\n';
      }
      str+='<tr>\n' +
              '          <td>'+((page.pageNum-1)*page.pageSize+i+1)+'</td>\n' +
              '          <td>'+audit[i].firmName+'</td>\n' +
              '          <td>'+audit[i].firmFounder+'</td>\n' +
              '          <td>'+audit[i].firmTel+'</td>\n' +
              '          <td>'+audit[i].firmAddress+'</td>\n' +
              '          <td>'+status+'</td>\n' +
              '          <td>'+audit[i].createTime+'</td>\n' +
              '          <td>'+audit[i].creator.uName+'</td>\n' +
              '          <td>\n' +
              '<a href="manufacturerView.html?id='+audit[i].firmId+'" class="tablelink">查看详情</a>   ' +
              lor+
              '          </td>\n' +
              '        </tr>'
    }


    $('#tList').html(str);
    $('.tablelist tbody tr:odd').addClass('odd');

    pageNum=page.pageNum;
    $('#totalCount').html(page.totalCount); //添加总记录数
    $('#pageNum').html(page.pageNum) ;  //当前所在页
    console.log(page);
    //页码显示
    layui.use("laypage", function () {
      var laypage = layui.laypage;
      laypage.render({
        elem: "page",                       //页码所放的位置 id属性
        count: page.totalCount,             //总记录数
        theme: '#eb5409',
        limit: page.pageSize,               //每页的数据
        limits: [5, 8, 12],                 //每页可访问的数据量
        curr: page.pageNum,                 //当前页
        layout: ['prev', 'page', 'next', 'limit', 'count','skip'],
        jump: function (obj, first) {
          page.pageNum = obj.curr
          pageSize = obj.limit
          if (!first) {
            loadPurchase(page.pageNum, pageSize,conn);
          }
        }
      })
    })
  }
</script>
</body>
</html>
